#ifndef __WIZ_BNF_ACTION_HPP__SHANHAOBO_19800429__
#define __WIZ_BNF_ACTION_HPP__SHANHAOBO_19800429__

#include "../Parser/WizBNFParserUnary.hpp"

namespace Wiz
{
    namespace BNF
    {
        namespace Action
        {
            template <typename ParserT, typename ActionT>
            class Type : public ::Wiz::BNF::Parser::Unary::Type<ParserT, ::Wiz::BNF::Parser::Type<Type<ParserT, ActionT>>>
            {
                WIZ_DECLARE_CLASS_THIS(Type);
                typedef ::Wiz::BNF::Parser::Unary::Type<ParserT, ::Wiz::BNF::Parser::Type<Type<ParserT, ActionT>>>  tSuper;
            public:
                template <typename ScannerT>
                struct Result
                {
                    typedef typename ::Wiz::BNF::Parser::Result<ParserT, ScannerT>::tType   tType;
                };
            public:
                Type(ParserT const& Prsr, ActionT const& Act) : tSuper(Prsr), m_Actor(Act)
                {}
            public:
                template <typename ScannerT>
                typename ::Wiz::BNF::Parser::Result<tThis, ScannerT>::tType
                ParseImpl(ScannerT const& Scan) const
                {
                    typedef typename ScannerT::tIterator                                    tIterator;
                    typedef typename ::Wiz::BNF::Parser::Result<tThis, ScannerT>::tType     tResult;

                    Scan.AtEnd();
                    tIterator StartItr = Scan.m_Curr;
                    tResult Rslt = this->Subject().Parse(Scan);
                    if (Rslt.IsValid())
                    {
                        Scan.DoAction(m_Actor, Rslt.Value(), StartItr, Scan.m_Curr);
                    }
                    return Rslt;
                }
            private:
                ActionT m_Actor;
            };
        } /// end of namespace Action
    } /// end of namespace BNF
} /// end of namespace Wiz

#endif /*__WIZ_BNF_ACTION_HPP__SHANHAOBO_19800429__*/
